from typing import List

from ninja import Router, Query
from ninja.pagination import paginate

from apps.commom.water_droplets import WaterDropletsRecordSerializer
from apps.manager.water_droplets_record.schema import WaterDropletsRecordFilterSchema, WaterDropletsRecordResponseSchema
from models.models import WaterDropletsRecord
from utils.auth import ManagerAuthBearer
from utils.decorators import handle_exception
from utils.paginations import MyPagination

water_droplets_record_router = Router(tags=["水滴记录"], auth=ManagerAuthBearer())


@water_droplets_record_router.get("/water_droplets_records", summary="获取水滴记录",
                                  response=List[WaterDropletsRecordResponseSchema])
@handle_exception("获取水滴记录失败")
@paginate(MyPagination)
def get_water_droplets_records(request, filters: WaterDropletsRecordFilterSchema = Query(...)):
    records = WaterDropletsRecord.objects.all()
    records = filters.filter(records)
    return records
